home *** CD-ROM | disk | FTP | other *** search
- The following is a pascal assignment that I had in data structures. It
- implements a graph for analyzing data. It is probably of use to you if you
- want to learn something about graph data structures. Before digging into the
- code perhaps you want to get a book on data structures and read up on what a
- graph is. Happy computing!!
-
- Chris Maeder
-
-
- GRAPH ASSIGNMENT
-
- Data Structures
- Fall 1985
-
- Write a Pascal program to find the minimum path length (distance) between
- various cities. The input to the program will consist of three parts. First
- is a list of edges (cities with a distance of one between them) from which
- the adjacency matrix can be constructed. Finally is a list of cities for
- which you are to find distances. Output will be the distances between the
- queries.
-
- Input:
-
- Input starts with a list of city names, one per line. These are the
- labels of the nodes for the graph. A 'ZZZ' on a line by itself ends the
- list.
-
- After this comes pairs of city names giving the edges of the graph. The
- names are separated by one blank (no blanks occur within a name). From
- these pairs the adjacency matrix can be constructed. The list of edges
- is ended by a 'ZZZ ZZZ' on a line by itself.
-
- Finally come queries consisting of pairs of city names. Find the minimum
- path lengths for these pairs. Read queries until the end of the file is
- hit.
-
- Example input data:
-
- Milwaukee
- Chicago
- St_Louis
- ZZZ
- Milwaukee Chicago
- St_Louis Milwaukee
- ZZZ ZZZ
- Chicago St_Louis
-
- Output:
-
- Echo print everything read in. Use labels.
-
- Print each pair of the query cities and give the path length between them.
-
- Notes and Requirements:
-
- 1. The graph has at most 15 nodes (cities).
- 2. The name of each city is at most 12 characters.
- 3. There are at most 20 queries.
- 4. The adjacency matrix must be a boolean array.
- 5. A city found in the list of edges or in a query may not be in the
- initial city list. If so, print an error message, ignore that pair of
- cities, and go on to the next pair of cities.
- 6. It is possible no path will exist between some cities.
- 7. The values in a cell change arbitrarily through the versions. You
- must catch the first occurrence of a 'true' in a cell to get the
- minimum distance.
-
-
-